package practice;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class 读取xml文件 {
    public static void main(String[] args) throws Exception{
        Document document = new SAXReader().read(new File("C:\\develop\\code\\javase\\xml-枚举-注解\\src\\practice\\students.xml"));
        Element rootElement = document.getRootElement();
        List<Element> students = rootElement.elements("student");
        for (Element student : students) {
            Attribute id = student.attribute("id");
            System.out.println(id.getValue());

            Element name = student.element("name");
            String text = name.getText();
            System.out.println(text);

            Element age = student.element("age");
            System.out.println(age.getText());

            Element address = student.element("address");
            System.out.println(address.getText());
        }
    }
}
